﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using sipfe.model.dataAccess;

namespace sipfe.Controllers.Mante
{ 
    public class AAAController : Controller
    {
        private BDSIPFEEntities db = new BDSIPFEEntities();

        //
        // GET: /AAA/

        public ViewResult Index()
        {
            var sipmaepersona = db.SIPMaePersona.Include(s => s.SIPDetCompendio).Include(s => s.SIPDetCompendio1).Include(s => s.SIPDetCompendio2).Include(s => s.SIPDetCompendio3).Include(s => s.SIPMaeUsuario);
            return View(sipmaepersona.ToList());
        }

        //
        // GET: /AAA/Details/5

        public ViewResult Details(decimal id)
        {
            SIPMaePersona sipmaepersona = db.SIPMaePersona.Find(id);
            return View(sipmaepersona);
        }

        //
        // GET: /AAA/Create

        public ActionResult Create()
        {
            ViewBag.nIdeTipoGenero = new SelectList(db.SIPDetCompendio, "nIdeDetalle", "vCodElemento");
            ViewBag.nIdeCodPaisDoc = new SelectList(db.SIPDetCompendio, "nIdeDetalle", "vCodElemento");
            ViewBag.nIdeTipoDocum = new SelectList(db.SIPDetCompendio, "nIdeDetalle", "vCodElemento");
            ViewBag.nIdeTipoPer = new SelectList(db.SIPDetCompendio, "nIdeDetalle", "vCodElemento");
            ViewBag.nIdeUsuReg = new SelectList(db.SIPMaeUsuario, "nIdeUsu", "vCodUsuario");
            return View();
        } 

        //
        // POST: /AAA/Create

        [HttpPost]
        public ActionResult Create(SIPMaePersona sipmaepersona)
        {
            if (ModelState.IsValid)
            {
                db.SIPMaePersona.Add(sipmaepersona);
                db.SaveChanges();
                return RedirectToAction("Index");  
            }

            ViewBag.nIdeTipoGenero = new SelectList(db.SIPDetCompendio, "nIdeDetalle", "vCodElemento", sipmaepersona.nIdeTipoGenero);
            ViewBag.nIdeCodPaisDoc = new SelectList(db.SIPDetCompendio, "nIdeDetalle", "vCodElemento", sipmaepersona.nIdeCodPaisDoc);
            ViewBag.nIdeTipoDocum = new SelectList(db.SIPDetCompendio, "nIdeDetalle", "vCodElemento", sipmaepersona.nIdeTipoDocum);
            ViewBag.nIdeTipoPer = new SelectList(db.SIPDetCompendio, "nIdeDetalle", "vCodElemento", sipmaepersona.nIdeTipoPer);
            ViewBag.nIdeUsuReg = new SelectList(db.SIPMaeUsuario, "nIdeUsu", "vCodUsuario", sipmaepersona.nIdeUsuReg);
            return View(sipmaepersona);
        }
        
        //
        // GET: /AAA/Edit/5
 
        public ActionResult Edit(decimal id)
        {
            SIPMaePersona sipmaepersona = db.SIPMaePersona.Find(id);
            ViewBag.nIdeTipoGenero = new SelectList(db.SIPDetCompendio, "nIdeDetalle", "vCodElemento", sipmaepersona.nIdeTipoGenero);
            ViewBag.nIdeCodPaisDoc = new SelectList(db.SIPDetCompendio, "nIdeDetalle", "vCodElemento", sipmaepersona.nIdeCodPaisDoc);
            ViewBag.nIdeTipoDocum = new SelectList(db.SIPDetCompendio, "nIdeDetalle", "vCodElemento", sipmaepersona.nIdeTipoDocum);
            ViewBag.nIdeTipoPer = new SelectList(db.SIPDetCompendio, "nIdeDetalle", "vCodElemento", sipmaepersona.nIdeTipoPer);
            ViewBag.nIdeUsuReg = new SelectList(db.SIPMaeUsuario, "nIdeUsu", "vCodUsuario", sipmaepersona.nIdeUsuReg);
            return View(sipmaepersona);
        }

        //
        // POST: /AAA/Edit/5

        [HttpPost]
        public ActionResult Edit(SIPMaePersona sipmaepersona)
        {
            if (ModelState.IsValid)
            {
                db.Entry(sipmaepersona).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            ViewBag.nIdeTipoGenero = new SelectList(db.SIPDetCompendio, "nIdeDetalle", "vCodElemento", sipmaepersona.nIdeTipoGenero);
            ViewBag.nIdeCodPaisDoc = new SelectList(db.SIPDetCompendio, "nIdeDetalle", "vCodElemento", sipmaepersona.nIdeCodPaisDoc);
            ViewBag.nIdeTipoDocum = new SelectList(db.SIPDetCompendio, "nIdeDetalle", "vCodElemento", sipmaepersona.nIdeTipoDocum);
            ViewBag.nIdeTipoPer = new SelectList(db.SIPDetCompendio, "nIdeDetalle", "vCodElemento", sipmaepersona.nIdeTipoPer);
            ViewBag.nIdeUsuReg = new SelectList(db.SIPMaeUsuario, "nIdeUsu", "vCodUsuario", sipmaepersona.nIdeUsuReg);
            return View(sipmaepersona);
        }

        //
        // GET: /AAA/Delete/5
 
        public ActionResult Delete(decimal id)
        {
            SIPMaePersona sipmaepersona = db.SIPMaePersona.Find(id);
            return View(sipmaepersona);
        }

        //
        // POST: /AAA/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(decimal id)
        {            
            SIPMaePersona sipmaepersona = db.SIPMaePersona.Find(id);
            db.SIPMaePersona.Remove(sipmaepersona);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}